﻿//-----------------------------------------------------------------------
// <copyright file="ViewStateResultAdapter.cs" company="Sławomir Rosiek">
//     Copyright (c) Sławomir Rosiek. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Rosieks.Web.Flow
{
    using System.Web;
    using System.Web.Mvc;
    using Rosieks.Web.Flow.Html;
    using Rosieks.Web.Flow.Metadata;

    public class ViewStateResultAdapter : WebflowElementResultAdapterBase<ViewState>
    {
        public override ActionResult CreateResult(ViewState element, ControllerContext context)
        {
            context.Controller.ViewData[HtmlExtensions.WebflowModelViewDataKey] = WebflowContext.GetCurrent(context.HttpContext).Model;
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            return new ViewResult
            {
                ViewName = element.ViewPath,
                ViewData = context.Controller.ViewData,
                TempData = context.Controller.TempData,
            };
        }
    }
}
